﻿using System.Web.Mvc;
using smp.ButterflyCakes.Models.InputModels.Schedule;
using smp.ButterflyCakes.Models.ViewModels.Schedule;
using smp.ButterflyCakes.Repository.Implementation;
using smp.ButterflyCakes.Repository.Interfaces;

namespace smp.ButterflyCakes.Web.Controllers
{
    public partial class ScheduleController : BaseController
    {
        private readonly IScheduleRepository _scheduleRepository;

        public ScheduleController(ILog log, ICache cache, IScheduleRepository scheduleRepository) 
            : base(log, cache)
        {
            _scheduleRepository = scheduleRepository;
        }

        public ScheduleController()
        {
            _scheduleRepository = new ScheduleRepository();
        }

        public virtual ActionResult Index()
        {
            var data = new DateModel();
            return View(data);
        }

        [HttpPost]
        public virtual ActionResult Month(SelectMonthInput model)
        {
            var data = _scheduleRepository.GetSchedule(model.DateModel);
            return PartialView("Month", data);
        }

        [HttpPost]
        public virtual ActionResult NextMonth(SelectMonthInput model)
        {
            var dateModel = model.DateModel;
            dateModel.NextMonth();
            return Month(new SelectMonthInput {Month = dateModel.DisplayMonth, Year = dateModel.DisplayYear});
        }

        [HttpPost]
        public virtual ActionResult PreviousMonth(SelectMonthInput model)
        {
            var dateModel = model.DateModel;
            dateModel.PreviousMonth();
            return Month(new SelectMonthInput { Month = dateModel.DisplayMonth, Year = dateModel.DisplayYear });
        }

        [HttpGet]
        public virtual ActionResult Day(string id)
        {
            var data = _scheduleRepository.GetScheduleDay(new DateModel(id));
            return View("Day", data);
        }
    }
}
